package com.ropeok.controller;
import com.ropeok.common.ResponseResult;
import com.ropeok.entity.Role;
import com.ropeok.service.RoleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
 * @BelongsProject: training-mission
 * @BelongsPackage: com.ropeok.controller
 * @Author: zhofeifan
 * @CreateTime: 2022-08-29  10:23
 * @Description: Role的Controller
 * @Version: 1.0
 */
public class RoleController {
    private RoleService roleService;

    @GetMapping("/role/{id}")
    public ResponseResult findRoleByID(@PathVariable long id) {
        Role role = roleService.findRoleById(id);
        if (role == null) {
            //说明没有改用户
            return new ResponseResult(444, "没有角色");
        }
        return new ResponseResult(666, "操作成功", role);
    }

    @GetMapping("/role")
    public ResponseResult getRoleList() {
        List<Role> list = roleService.getRoleList();
        return new ResponseResult(666, "操作成功", list);
    }

    @PostMapping("/role")
    public ResponseResult addRole(@RequestBody Role role) {
        roleService.addRole(role);
        return new ResponseResult(666, "操作成功");
    }
}
